Page({
  data: {
    startX: 0, // 触摸起始位置
    textStyle: '' // item的样式
  },
  // 获取DOM节点
  // 手指放到触摸屏上触发
  handleTouchStart (e) {
    // 判断是否为一个触发点
    if (e.touches.length === 1) {
      this.setData({
        startX: e.touches[0].clientX
      })
    }
  },
  // 手指移动时触发
  handleTouchMove (e) {
    let that = this
    if (e.touches.length === 1) {
      // 获取移动的坐标
      let moveX = e.touches[0].clientX
      let disX = that.data.startX - moveX
      if (disX > 0) { // 手指向左移
        that.setData({
          textStyle: `left: ${-1 * disX}px`
        })
        if (disX >= 150) {
          that.setData({
            textStyle: `left: -150px`
          })
        }
      } else if (disX <= 0) { // 手指向右移
        that.setData({
          textStyle: `left: 0px`
        })
      }
    }
  },
  // 手指离开屏幕的那一刻
  handleTouchEnd (e) {
    if (e.touches.length === 1) {
      let endX = e.touches[0].clientX
      let disX = this.data.startX - endX
      if (disX > 80) {
        that.setData({
          textStyle: `left: ${-1 * disX}px`
        })
      } else if (disX <= 80) {
        that.setData({
          textStyle: `left: 0px`
        })
      }
    }
  }
})